/* $RCSFile: ADNDynActivitymimeattachment.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/CRMWrapper3/DynEntities/ADNDynActivitymimeattachment.cs $
 * $log$
 * Revision 19 2010/10/02 14:01:48  christian.surieux
 *   Corrected a bug in allmost everyADNDyn file for PrimaryFieldVualue
 * Revision 6 2010/08/06 19:56:32  christian.surieux
 *   Added Log to All cs files
 */

/* Copyrights Christian Surieux 2010 */
/* Class ADNDynActivitymimeattachment */
/* Date 2010-01-06 16:06:32Z */

using System;
using System.Diagnostics;
using System.Collections;
using System.ComponentModel;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Globalization;
using System.Web.Services.Protocols;

using CrmSdk;

namespace AddonNice.CRMWrapper
{
    public class ADNDynActivitymimeattachment : ADNDynCommonDoc
    {
        protected class Ftor: DFactor
        {
            public Ftor() : base(CrmStr.activitymimeattachment)
            {}

            public override Type DynType
            { get { return typeof(ADNDynActivitymimeattachment); } }

            public override string DynTypename
            { get { return CrmStr.activitymimeattachment; } }

            public override DynEntity Build()
            {   return new ADNDynActivitymimeattachment();}

            public override DynEntity Build(CRMWrapperBase w, InternalDynamicEntity dEntity, PropertyDescriptorCollection wproperties)
            {   return new ADNDynActivitymimeattachment(w, dEntity, wproperties, null);}

            public override DynEntity Build(CRMWrapperBase w, string PrimaryFieldValue)
            {   return new ADNDynActivitymimeattachment(w,PrimaryFieldValue);}

            public override DynEntity Build(CRMWrapperBase w,Guid PrimaryKeyValue)
            {   return new ADNDynActivitymimeattachment(w,PrimaryKeyValue);}
        }

        static ADNDynActivitymimeattachment(){new Ftor();} 
        
        public override bool HasOwnerProperty
        {
            get { return false; }
        }
        
        public override bool HasOwningBusinessUnitProperty
        { get { return true; } }
        
        public override string SchemaName
        {
           get
           {
               if ( string.IsNullOrEmpty(_SchemaName) )
                    _SchemaName =   CrmStr.activitymimeattachment;
               return _SchemaName;
           }
           set{}
        }

        public override ADNTypeCodes ADNTypeCode
        {   get{ return ADNTypeCodes.ActivityMimeAttachment ; }}


        public override int ObjectTypeCode
        {
           get
           {
               if ( _ObjectTypeCode == 0 )
                    _ObjectTypeCode    =   1001;
               return _ObjectTypeCode;
           }
           set{}
        }
        
        public ADNDynActivitymimeattachment() : base() { }
        
        public ADNDynActivitymimeattachment(CRMWrapperBase w,string PrimaryFieldValue)
            : base(w,CrmStr.activitymimeattachment)
        {
            if ( PrimaryFieldValue != string.Empty )
                filename = PrimaryFieldValue;
        }
        
        public ADNDynActivitymimeattachment(CRMWrapperBase w,Guid CrmId) : base(w,CrmStr.activitymimeattachment,CrmId) { }
        
        public ADNDynActivitymimeattachment(CRMWrapperBase w,InternalDynamicEntity e) : base(w,CrmStr.activitymimeattachment,e,null,null) { }
        
        public ADNDynActivitymimeattachment(CRMWrapperBase w,InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s) : base(w,CrmStr.activitymimeattachment,e,prop,s) { }
        
        public ADNDynActivitymimeattachment(ResetWrapperHandler fn,string PrimaryFieldValue)
            : base(fn,CrmStr.activitymimeattachment)
        {
            if ( PrimaryFieldValue != string.Empty )
                filename = PrimaryFieldValue;
        }
        
        public ADNDynActivitymimeattachment(ResetWrapperHandler fn,Guid CrmId) : base(fn,CrmStr.activitymimeattachment,CrmId) { }
        
        public ADNDynActivitymimeattachment(ResetWrapperHandler fn,InternalDynamicEntity e) : base(fn,CrmStr.activitymimeattachment,e,null,null) { }
        
        public ADNDynActivitymimeattachment(ResetWrapperHandler fn,InternalDynamicEntity e,PropertyDescriptorCollection prop,InternalColumnSet s) : base(fn,CrmStr.activitymimeattachment,e,prop,s) { }

        /* Properties */

        [CrmDynAttribute(CrmStr.activitymimeattachment)]
        public Guid activitymimeattachmentid
        {
            get{ return KeyPropertyValue(CrmStr.activitymimeattachmentid); }
            set{ AddKeyProperty(CrmStr.activitymimeattachmentid,value); }
        }

        protected override void SetCrmIdProperty(Guid crmId)
        {
            if ( !dicProperty.ContainsKey(CrmStr.activitymimeattachmentid) || KeyPropertyValue(CrmStr.activitymimeattachmentid) != crmId )
                activitymimeattachmentid = crmId;
        }
        public override Guid PrimaryKeyGuidValue
        {
            get{ return activitymimeattachmentid; }
            set { activitymimeattachmentid = value; }
        }
        public override string PrimaryFieldName
        {
            get{ return CrmStr.filename; }
            set{}
        }

        public override string PrimaryFieldStringValue
        {
            get
            {
                return filename;
            }
            set
            {
                filename =   value;
            }
        }

        [CrmDynAttribute(CrmStr.activitymimeattachment)]
        public Guid activityid
        {
            get{ return LookupPropertyValue(CrmStr.activityid); }
            set{ AddLookupProperty(CrmStr.activityid,CrmStr.activity,value); }
        }

        [CrmDynAttribute(CrmStr.activitymimeattachment)]
        public int attachmentnumber
        {
            get{ return NumberPropertyValue(CrmStr.attachmentnumber); }
            set{ AddNumberProperty(CrmStr.attachmentnumber,value); }
        }

        [CrmDynAttribute(CrmStr.activitymimeattachment)]
        public string body
        {
            get{ return StringPropertyValue(CrmStr.body); }
            set{ AddStringProperty(CrmStr.body,value); }
        }

        [CrmDynAttribute(CrmStr.activitymimeattachment)]
        public Guid owningbusinessunit
        {
            get{ return LookupPropertyValue(CrmStr.owningbusinessunit); }
            set{ AddLookupProperty(CrmStr.owningbusinessunit,CrmStr.businessunit,value); }
        }

        [CrmDynAttribute(CrmStr.activitymimeattachment)]
        public Guid owninguser
        {
            get{ return LookupPropertyValue(CrmStr.owninguser); }
            set{ AddLookupProperty(CrmStr.owninguser,CrmStr.systemuser,value); }
        }

        [CrmDynAttribute(CrmStr.activitymimeattachment)]
        public string subject
        {
            get{ return StringPropertyValue(CrmStr.subject); }
            set{ AddStringProperty(CrmStr.subject,value); }
        }
        
        #region Utilities
           
        static string[] ExactivitymimeattachmentAttributes  =   new string[]{CrmStr.activitymimeattachmentid,
                                                                CrmStr.subject,
                                                                CrmStr.attachmentnumber,
                                                                CrmStr.body,
                                                                CrmStr.activityid,
                                                                CrmStr.mimetype,
                                                                CrmStr.filename,
                                                                CrmStr.filesize
                                                            };

        
        static string[] activitymimeattachmentAttributes    =   new string[]{CrmStr.activitymimeattachmentid,
                                                                CrmStr.subject,
                                                                CrmStr.attachmentnumber,
                                                                CrmStr.body,
                                                                CrmStr.activityid,
                                                                CrmStr.filename,
                                                                CrmStr.filesize
                                                            };

        /// <summary>
        /// Build a DataTable to display in in RadGrid
        /// </summary>
        public static DataTable ReadForGrid(CRMWrapperBase wrapper,ResetWrapperHandler fn,bool extendedView)
        {
            if (CRMDynTraceSwitch.Sw.TraceVerbose || CRMDynTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynActivitymimeattachment ReadForGrid BEG extendedView: {0}.",extendedView),(CRMDynTraceSwitch.Sw.TraceVerbose)? CRMDynTraceSwitch.Sw.Info:CRMDynTraceSwitch.Sw.Info);
            DataTable Tb                                        =   null;
            try
            {
                InternalQueryExpression qe                      =   new InternalQueryExpression();
                qe.EntityName                                   =   CrmStr.activitymimeattachment;
                InternalColumnSet RequestCols                   =   new InternalColumnSet();
                InternalFilterExpression fi                     =   new InternalFilterExpression();
                InternalConditionExpression ex                  =   new InternalConditionExpression();
                if ( extendedView )
                        RequestCols.Attributes      =   ExactivitymimeattachmentAttributes;
                else    RequestCols.Attributes      =   activitymimeattachmentAttributes;
                ex.AttributeName                                =   CrmStr.filename;
                ex.Operator                                     =   InternalConditionOperator.NotNull;
                ex.Values                                       =   new object[0];
                fi.Conditions                                   =   new InternalConditionExpression[]{ex};
                qe.ColumnSet                                    =   RequestCols;
                qe.Criteria                                     =   fi;
                GenericDynQueryMultiple<ADNDynActivitymimeattachment> allEntQuery      =   new GenericDynQueryMultiple<ADNDynActivitymimeattachment>(wrapper,fn,CrmStr.activitymimeattachment);
                Tb                                              =   allEntQuery.retrieveDatatable(qe);
            }
            catch (Exception ex)
            {
                if ( CRMDynTraceSwitch.Sw.TraceError )
                    Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]ADNDynActivitymimeattachment ReadForGrid ex: {0}", ex),CRMDynTraceSwitch.Sw.Info);
                throw;
            }
            if (CRMDynTraceSwitch.Sw.TraceVerbose || CRMDynTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynActivitymimeattachment ReadForGrid END Count: {0}",Tb.Rows.Count),(CRMDynTraceSwitch.Sw.TraceVerbose)? CRMDynTraceSwitch.Sw.Info:CRMDynTraceSwitch.Sw.Info);
            return Tb;
        }

        /// <summary>
        /// Build a SortedList 
        /// </summary>
        static public SortedList<Guid,ADNDynActivitymimeattachment>  ReadAll(CRMWrapperBase wrapper,ResetWrapperHandler fn)
        {
            if (CRMDynTraceSwitch.Sw.TraceVerbose || CRMDynTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine("[V]ADNDynActivitymimeattachment ReadAll BEG.",(CRMDynTraceSwitch.Sw.TraceVerbose)? CRMDynTraceSwitch.Sw.Info:CRMDynTraceSwitch.Sw.Info);
            SortedList<Guid,ADNDynActivitymimeattachment> Lst      =   null;
            try
            {
                InternalQueryExpression qe                      =   new InternalQueryExpression();
                qe.EntityName                                   =   CrmStr.activitymimeattachment;
                InternalFilterExpression fi                     =   new InternalFilterExpression();
                InternalConditionExpression ex                  =   new InternalConditionExpression();
                ex.AttributeName                                =   CrmStr.filename;
                ex.Operator                                     =   InternalConditionOperator.NotNull;
                ex.Values                                       =   new object[0];
                fi.Conditions                                   =   new InternalConditionExpression[]{ex};
                qe.ColumnSet                                    =   new InternalAllColumns();
                qe.Criteria                                     =   fi;
                GenericDynQueryMultiple<ADNDynActivitymimeattachment> allEntQuery      =   new GenericDynQueryMultiple<ADNDynActivitymimeattachment>(wrapper,fn,CrmStr.activitymimeattachment);
                Lst                                             =   allEntQuery.retrieveSortedList(qe);
            }
            catch (Exception ex)
            {
                if ( CRMDynTraceSwitch.Sw.TraceError )
                    Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[E]ADNDynActivitymimeattachment ReadAll ex: {0}", ex),CRMDynTraceSwitch.Sw.Info);
                throw;
            }
            if (CRMDynTraceSwitch.Sw.TraceVerbose || CRMDynTraceSwitch.Sw.TraceVerbose)
                Trace.WriteLine( string.Format(CultureInfo.InvariantCulture,"[V]ADNDynActivitymimeattachment ReadAll END Count: {0}",Lst.Count),(CRMDynTraceSwitch.Sw.TraceVerbose)? CRMDynTraceSwitch.Sw.Info:CRMDynTraceSwitch.Sw.Info);
            return Lst;
        }

        #endregion
   }
}